// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Grab Bar Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 74 : TYPE_GRABBAR

// Function declarations
reserve function GrabBar_DebugDraw
reserve function GrabBar_DebugSpawn

// Static Values

// Tables

function GrabBar_DebugDraw
	DrawSprite(0)
end function


function GrabBar_DebugSpawn
	CreateTempObject(TypeName[Grab Bar], 0, object.xpos, object.ypos)
	object[tempObjectPos].value0 = 60
end function


event ObjectMain
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		temp2 = 0
		if object[currentPlayer].type == TypeName[Tails Object]
			temp3 = 0xF0000
		else
			temp3 = 0x140000
		end if
		temp0 = object.xpos
		temp0 += temp3
		temp0 -= object[currentPlayer].xpos
		Abs(temp0)
		if temp0 <= 0x40000
			temp0 = object.ypos
			temp0 -= object[currentPlayer].ypos
			temp1 = temp0
			Abs(temp0)
			if temp0 <= 0x120000
				object[currentPlayer].animation = ANI_CLINGING
				object[currentPlayer].direction = FLIP_NONE
				object[currentPlayer].xpos = object.xpos
				object[currentPlayer].xpos += temp3
				temp2 = 1
			else
				if object[currentPlayer].animation == ANI_CLINGING
					object[currentPlayer].ypos = object.ypos
					if temp1 < 0
						object[currentPlayer].ypos += 0x120000
					else
						object[currentPlayer].ypos -= 0x120000
					end if
					temp2 = 1
				end if
			end if
			if temp2 != 0
				if object[currentPlayer].jumpPress != 0
					object[currentPlayer].animation = ANI_FANROTATE
				end if
				if object.frame == 1
					object[currentPlayer].animation = ANI_FANROTATE
				else
					if currentPlayer == 0
						object.value0--
						if object.value0 == 0
							object.frame = 1
						end if
					end if
				end if
			end if
		end if
	next
end event


event ObjectDraw
	DrawSprite(object.frame)
end event


event ObjectStartup
	LoadSpriteSheet("LZ/Objects.gif")
	SpriteFrame(-4, -32, 8, 64, 35, 1)
	SpriteFrame(-4, -32, 14, 64, 44, 1)
	foreach (TypeName[Grab Bar], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].value0 = object[arrayPos0].propertyValue
		object[arrayPos0].value0 *= 60
	next
	SetTableValue(TypeName[Grab Bar], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(GrabBar_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(GrabBar_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
